/* Wireless Nuevas */
#ifndef NEW_WIRELESS_H
#define NEW_WIRELESS_H

//just in case...
#ifndef DEBUG_MINE_1
# undef DEBUG_MINE_1
#endif

# ifdef DEBUG_MINE_1
#  define DEBUG( T , args... )  printk( KERN_DEBUG T, ##args)
#  define DEBUG2( T , args... )  printk( KERN_DEBUG T, ##args)
# else
#  define DEBUG( T , args... ) while(0){}
#  define DEBUG2( T , args... ) while(0){}
# endif

# define Wb32_RegisterRead				SIOCIWFIRSTPRIV
# define Wb32_RegisterWrite				SIOCIWFIRSTPRIV + 1
# define IOCTL_PRIV_SET_REGION			SIOCIWFIRSTPRIV + 2
# define IOCTL_PRIV_GET_REGION			SIOCIWFIRSTPRIV + 3
# define IOCTL_PRIV_SET_IBSS_FREQUENCY	SIOCIWFIRSTPRIV + 4
# define IOCTL_PRIV_GET_IBSS_FREQUENCY	SIOCIWFIRSTPRIV + 5
# define IOCTL_PRIV_SET_IBSS_MODE		SIOCIWFIRSTPRIV + 6
# define IOCTL_PRIV_GET_IBSS_MODE		SIOCIWFIRSTPRIV + 7
# define IOCTL_PRIV_GET_SCAN_LIST		SIOCIWFIRSTPRIV + 8
# define IOCTL_PRIV_SET_SCAN_LIST		SIOCIWFIRSTPRIV + 9

//Added by WangJS 2005.12.9
# define IOCTL_PRIV_SET_GENIES			SIOCIWFIRSTPRIV + 10
//Added by WangJS 2006.6.22
# define IOCTL_PRIV_GET_DRIVER_VER		SIOCIWFIRSTPRIV + 11
//Added by WangJS 2005.12.6
# define IOCTL_PRIV_SET_WPA_PASSWORD		SIOCIWFIRSTPRIV + 12
//Added by WangJS 2006.6.3
# define IOCTL_PRIV_GET_SSID_INFO		SIOCIWFIRSTPRIV + 13
//Added by WangJS 2006.9.7
//# define IOCTL_PRIV_SET_RATE				SIOCIWFIRSTPRIV + 14

// Autor: Leandro Costantino - Pixart SRL <> : Port from original  Winbound Wireless Driver
// Distro: Rxart Desktop  kernel 2.6.22-pixart-panda
//
# define NICKNAME "IS89C35"
//RSSI -> Signal / Quality
# define MIN_RSSI -26
# define MAX_RSSI -110
# define AV_RSSI ( MAX_RSSI - MIN_RSSI)
//Estimation
# define GET_QUALITY_PERCENTAGE(rssi) (int)(((rssi - MIN_RSSI)*100)/AV_RSSI)

# define KEYS_AVAILABLE 4    //should be ok?
# define MAX_RATES_BY_VENDOR 11
# define MAX_KEY_SIZE    13
# define MIN_KEY_SIZE    5
# define SSID_MAX_WPA_IE_LEN	40

int test_get_name(struct net_device *dev, struct iw_request_info *info, char *name, char *extra);
int test_set_scan(struct net_device *dev, struct iw_request_info *info, struct iw_point *srq, char *extra);
int test_get_scan(struct net_device *dev, struct iw_request_info *info, struct iw_point *srq, char *extra);
int test_set_freq(struct net_device *dev, struct iw_request_info *info, struct iw_freq *freq, char *extra);
int test_get_freq(struct net_device *dev, struct iw_request_info *info, struct iw_freq *freq, char *extra);
int test_get_range(struct net_device *dev,  struct iw_request_info *info, struct iw_point *wrq, char *extra);
int test_get_power(struct net_device *dev,  struct iw_request_info *info, struct iw_param *vwrq, char *extra);
int test_get_mode(struct net_device *dev, struct iw_request_info *info, __u32 *mode, char *extra);
int test_set_mode(struct net_device *dev, struct iw_request_info *info, __u32 *mode, char *extra);
int test_get_rate(struct net_device *dev, struct iw_request_info *info, struct iw_param *rrq, char *extra);
int test_set_rate(struct net_device *dev, struct iw_request_info *info, struct iw_param *rrq, char *extra);
int test_set_rts(struct net_device *dev, struct iw_request_info *info, struct iw_param *rts, char *extra);
int test_get_rts(struct net_device *dev, struct iw_request_info *info, struct iw_param *rts, char *extra);
int test_set_frag(struct net_device *dev, struct iw_request_info *info, struct iw_param *frag, char *extra);
int test_get_frag(struct net_device *dev, struct iw_request_info *info, struct iw_param *frag, char *extra);
int test_get_sens(struct net_device *dev, struct iw_request_info *info, struct iw_param *sens, char *extra);
int test_set_txpow(struct net_device *dev, struct iw_request_info *info,struct iw_param *txpow, char *extra);
int test_get_txpow(struct net_device *dev, struct iw_request_info *info,struct iw_param *txpow, char *extra);
int test_set_essid(struct net_device *dev, struct iw_request_info *info, struct iw_point *data, char *essid);
int test_get_essid(struct net_device *dev, struct iw_request_info *info, struct iw_point *data, char *essid);
int test_get_nick(struct net_device *dev, struct iw_request_info *info, struct iw_point *data, char *nick);
int test_get_wap(struct net_device *dev,	struct iw_request_info *info, struct sockaddr *ap_addr, char *extra);
int test_set_wap(struct net_device *dev,	struct iw_request_info *info, struct sockaddr *ap_addr, char *extra);

//PRIVATES
int  test_get_register(struct net_device *dev,    struct iw_request_info *info, struct iw_param *param, char *extra);
int test_set_register(struct net_device *dev,    struct iw_request_info *info, struct iw_param *param, char *extra);
int test_get_region( struct net_device *dev, struct iw_request_info *info, struct iw_point *data, char *region);
int test_set_region( struct net_device *dev, struct iw_request_info *info,   struct iw_point *data, char *region);
int test_get_ibss_freq(struct net_device *dev,    struct iw_request_info *info,	struct iw_point *data, char *region);
int test_set_ibss_freq(struct net_device *dev,    struct iw_request_info *info,	struct iw_point *data, char *region);
int test_get_ibss_mode(struct net_device *dev,    struct iw_request_info *info, struct iw_point *data, char *extra);
int test_set_ibss_mode(struct net_device *dev,    struct iw_request_info *info, struct iw_point *data, char *extra);
int test_get_scan_list(struct net_device *dev,    struct iw_request_info *info, struct iw_point *data, char *extra);
int test_scanning(struct net_device *dev,    struct iw_request_info *info, struct iw_point *data, char *extra);

/* TKIP Support inside the card, dont need suplicant in this case */
int test_set_pwd(struct net_device *dev, struct iw_request_info *info, struct iw_point *data, char *extra);
int test_set_ie(struct net_device *dev, struct iw_request_info *info, struct iw_point *data, char *extra);
int test_set_genie(struct net_device *dev, struct iw_request_info *info, struct iw_point *data, char *extra);
int test_get_ver(struct net_device *dev, struct iw_request_info *info, struct iw_point *param, char *extra);
int test_get_ssid_info(struct net_device *dev, struct iw_request_info *info, struct iw_point *param, char *extra);
int test_set_encode(struct net_device *dev, struct iw_request_info *info, struct iw_point *erq, char *key);
int test_get_encode(struct net_device *dev, struct iw_request_info *info, struct iw_point *erq, char *key);
int test_set_encodeext(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu,char *extra);
int test_get_encodeext(struct net_device *dev, struct iw_request_info *info,union iwreq_data *wrqu,char *extra);
int test_set_auth(struct net_device *dev,    struct iw_request_info *info, struct iw_point *data, char *extra);

#ifdef DEBUG_MINE_1
   struct iw_statistics *test_get_wireless_stats(struct net_device *ndev);
#endif

static const iw_handler test_iw_handler[] =
{
   (iw_handler) NULL,//test_config_commit,	/* SIOCSIWCOMMIT */
     (iw_handler) test_get_name,    	/* SIOCGIWNAME */
     (iw_handler) NULL,			/* SIOCSIWNWID */
     (iw_handler) NULL,			/* SIOCGIWNWID */
     (iw_handler) test_set_freq,		/* SIOCSIWFREQ */
     (iw_handler) test_get_freq,		/* SIOCGIWFREQ */
     (iw_handler) test_set_mode,		/* SIOCSIWMODE */
     (iw_handler) test_get_mode,		/* SIOCGIWMODE */
     (iw_handler) NULL,                  	/* SIOCSIWSENS */
     (iw_handler) test_get_sens,           		/* SIOCGIWSENS */
     (iw_handler) NULL,			/* SIOCSIWRANGE */
     (iw_handler) test_get_range,           /* SIOCGIWRANGE */
     (iw_handler) NULL,			/* SIOCSIWPRIV */
     (iw_handler) NULL,			/* SIOCGIWPRIV */
     (iw_handler) NULL,			/* SIOCSIWSTATS */
     (iw_handler) NULL,			/* SIOCGIWSTATS */
     (iw_handler) NULL,			/* SIOCSIWSPY */
     (iw_handler) NULL,			/* SIOCGIWSPY */
     (iw_handler) NULL,			/* -- hole -- */
     (iw_handler) NULL,			/* -- hole -- */
     (iw_handler) test_set_wap,		/* SIOCSIWAP */
     (iw_handler) test_get_wap,		/* SIOCGIWAP */
     (iw_handler) NULL,			/* -- hole -- */
     (iw_handler) NULL,       		/* SIOCGIWAPLIST */
     (iw_handler) test_set_scan,		/* SIOCSIWSCAN */
     (iw_handler) test_get_scan,		/* SIOCGIWSCAN */
     (iw_handler) test_set_essid,		/* SIOCSIWESSID */
     (iw_handler) test_get_essid,		/* SIOCGIWESSID */
     (iw_handler) NULL,         		/* SIOCSIWNICKN */
     (iw_handler) test_get_nick, 		/* SIOCGIWNICKN */
     (iw_handler) NULL,			/* -- hole -- */
     (iw_handler) NULL,			/* -- hole -- */
     (iw_handler) test_set_rate,		/* SIOCSIWRATE */
     (iw_handler) test_get_rate,		/* SIOCGIWRATE */
     (iw_handler) test_set_rts,		/* SIOCSIWRTS */
     (iw_handler) test_get_rts,		/* SIOCGIWRTS */
     (iw_handler) test_set_frag,		/* SIOCSIWFRAG */
     (iw_handler) test_get_frag,		/* SIOCGIWFRAG */

     (iw_handler) test_set_txpow,         		/* SIOCSIWTXPOW */
     (iw_handler) test_get_txpow,          		/* SIOCGIWTXPOW */
     (iw_handler) NULL,		/* SIOCSIWRETRY */
     (iw_handler) NULL,		/* SIOCGIWRETRY */
     (iw_handler) test_set_encode,		/* SIOCSIWENCODE */
     (iw_handler) test_get_encode,		/* SIOCGIWENCODE */
     (iw_handler) NULL,		/* SIOCSIWPOWER */
     (iw_handler) test_get_power,		/* SIOCGIWPOWER */ // VER EL REGISTRO
     (iw_handler) NULL,                      /* -- hole -- */
     (iw_handler) NULL,                      /* -- hole -- */
     (iw_handler) test_set_genie,                      /* SIOCSIWGENIE */
     (iw_handler) NULL,                      /* SIOCGIWGENIE */
     (iw_handler) test_set_auth,             /* SIOCSIWAUTH */
     (iw_handler) NULL,             /* SIOCGIWAUTH */
     (iw_handler) test_set_encodeext,        /* SIOCSIWENCODEEXT */
     (iw_handler) test_get_encodeext,        /* SIOCGIWENCODEEXT */
     (iw_handler) NULL,                      /* SIOCSIWPMKSA */
};

static const iw_handler test_private_handler[] =
{

   (iw_handler) test_get_register,
     (iw_handler) test_set_register,
     (iw_handler) test_set_region,                     /* nothing to get */
     (iw_handler) test_get_region,
     (iw_handler) test_set_ibss_freq,
     (iw_handler) test_get_ibss_freq,
     (iw_handler) test_set_ibss_mode,
     (iw_handler) test_get_ibss_mode,

     (iw_handler) test_get_scan_list,
     (iw_handler) test_scanning,
     (iw_handler) test_set_ie,
     (iw_handler) test_get_ver,
     (iw_handler) test_set_pwd,

     (iw_handler) test_get_ssid_info,
     //     (iw_handler) test_set_rate,
};

static const struct iw_priv_args test_private_args[] =
{
     { Wb32_RegisterRead, IW_PRIV_TYPE_NONE,	IW_PRIV_TYPE_CHAR | 4 , "get_register" },
     { Wb32_RegisterWrite, IW_PRIV_TYPE_CHAR | 4, 0, "set_register" },
     { IOCTL_PRIV_SET_REGION, IW_PRIV_TYPE_CHAR | 15, IW_PRIV_TYPE_NONE, "set_region" },
     { IOCTL_PRIV_GET_REGION, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | 15 , "get_region" },
     { IOCTL_PRIV_SET_IBSS_FREQUENCY, IW_PRIV_TYPE_INT | 1, 0, "set_ibss_freq" },
     { IOCTL_PRIV_GET_IBSS_FREQUENCY, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | 1, "get_ibss_freq" },
     { IOCTL_PRIV_SET_IBSS_MODE, IW_PRIV_TYPE_CHAR | 10, IW_PRIV_TYPE_NONE, "set_ibss_mode" },
     { IOCTL_PRIV_GET_IBSS_MODE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | 10, "get_ibss_mode" },

     { IOCTL_PRIV_GET_SCAN_LIST,IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | 15, "scan_list"},
     { IOCTL_PRIV_SET_SCAN_LIST, IW_PRIV_TYPE_BYTE | 0, IW_PRIV_TYPE_NONE, "scanning"},
     { IOCTL_PRIV_SET_GENIES, IW_PRIV_TYPE_CHAR | 15, IW_PRIV_TYPE_NONE, "set_ie"}, //Added by WangJS 2005.12.9, modifed 2005.12.27
     { IOCTL_PRIV_GET_DRIVER_VER,IW_PRIV_TYPE_NONE,IW_PRIV_TYPE_CHAR | 15, "get_ver"}, //Added by WangJS 2006.6.22
     { IOCTL_PRIV_SET_WPA_PASSWORD, IW_PRIV_TYPE_CHAR | 15, IW_PRIV_TYPE_NONE, "set_pwd"}, //Added by WangJS 2005.12.8, modified 2005.12.27
     { IOCTL_PRIV_GET_SSID_INFO,IW_PRIV_TYPE_NONE,IW_PRIV_TYPE_CHAR | 15, "get_ssid_info"}, //Added by WangJS 2006.6.30

};

static const struct iw_handler_def test_iw_handlers =
{

   .num_standard           = ARRAY_SIZE(test_iw_handler),
   .num_private            = ARRAY_SIZE(test_private_handler),
   .num_private_args       =ARRAY_SIZE(test_private_args),
   .standard               = (iw_handler *)test_iw_handler,
     .private                =(iw_handler *)test_private_handler,
     .private_args           =(struct iw_priv_args *) test_private_args,
     #ifdef DEBUG_MINE_1
     .get_wireless_stats     = test_get_wireless_stats,
     #else
     .get_wireless_stats     = NULL,
     #endif
};

// channel number -> channel freq.
void ChannelNumToFreq(UCHAR NetworkType, UCHAR ChannelNumber, ULONG *freq);

// channel freq. -> channel number
void FreqToChannelNum(UCHAR Band, UCHAR *ChannelNumber, ULONG freq);

#ifdef DEBUG_MINE_1
struct iw_statistics *test_get_wireless_stats(struct net_device *dev) {

   PADAPTER Adapter = dev->priv;
   struct iw_statistics *iw_stats = &Adapter->iw_stats;
//   unsigned int i, count;
  unsigned int t_rssi, t_qual;

   memset(iw_stats, 0, sizeof(struct iw_statistics));

   //SIMULATION for test......

   //lock..?

   t_rssi = t_qual = 0;

   iw_stats->qual.updated = IW_QUAL_NOISE_INVALID;

   iw_stats->qual.qual = 99;
   iw_stats->qual.level = 99;
   iw_stats->qual.updated |=
     IW_QUAL_QUAL_UPDATED|IW_QUAL_LEVEL_UPDATED;

   return iw_stats;
}
#endif

//EOF
#endif
